{{!
  Copyright IBM Corp. 2016, 2025
  SPDX-License-Identifier: BUSL-1.1
}}

<PageHeader as |p|>
  <p.top>
    <Hds::Breadcrumb>
      <Hds::Breadcrumb::Item
        @text="{{uppercase this.policyType}} policies"
        @route="vault.cluster.policies"
        @model={{this.policyType}}
        data-test-policy-list-link
      />
      <Hds::Breadcrumb::Item @text={{this.model.id}} @current={{true}} />
    </Hds::Breadcrumb>
  </p.top>
  <p.levelLeft>
    <h1 class="title is-3" data-test-policy-name="true">
      {{this.model.id}}
      {{#if this.model.enforcementLevel}}
        <Hds::Badge @text={{this.model.enforcementLevel}} aria-label="Enforcement level: {{this.model.enforcementLevel}}" />
      {{/if}}
    </h1>
  </p.levelLeft>
</PageHeader>
<Toolbar>
  <ToolbarActions>
    <DownloadButton
      class="toolbar-button"
      @color="secondary"
      @filename={{this.model.name}}
      @data={{this.model.policy}}
      @extension={{if (eq this.policyType "acl") this.model.format "sentinel"}}
      @text="Download policy"
    />
    {{#if (and (not-eq this.model.id "root") (or this.model.canUpdate this.model.canDelete))}}
      <ToolbarLink
        @route="vault.cluster.policy.edit"
        @models={{array this.policyType this.model.id}}
        data-test-policy-edit-toggle
      >
        Edit policy
      </ToolbarLink>
    {{/if}}
  </ToolbarActions>
</Toolbar>
<div class="box is-bottomless is-fullwidth is-marginless">
  {{#if this.model.policy}}
    <div class="field">
      <Hds::CodeBlock @value={{this.model.policy}} @hasCopyButton={{true}} @maxHeight="300px" @language="ruby" as |CB|>
        <CB.Title @tag="h3">
          Policy
        </CB.Title>
        <CB.Description>
          ({{if (eq this.policyType "acl") (concat this.uppercase this.model.format " format")}})
        </CB.Description>
      </Hds::CodeBlock>
    </div>
  {{/if}}
  {{#if this.model.paths}}
    <div class="field box is-shadowless no-bottom-padding is-marginless">
      <h2 class="title is-6">Paths</h2>
      <ul data-test-egp-paths>
        {{#each this.model.paths as |path|}}
          <li class="box has-slim-padding no-top-shadow is-marginless">
            <code class="has-text-black">{{path}}</code>
          </li>
        {{/each}}
      </ul>
    </div>
  {{/if}}
</div>